package scm.client;

import java.util.ArrayList;
import java.util.Date;

import scm.message.*;
import scm.server.MailServer;
/**
 * 
 * @author Benito
 *
 */
public class MailClient {

	private ArrayList<Message> messagelist = null;
	private String name; 
	private MailServer server;
	private int messageindex;
	
	public MailClient(String username){
		this.name = username;
		messageindex =0;
		messagelist = new ArrayList<Message>();
	}
	
	public int checkMessage(){
		return messagelist.size();
	}
	
	public void reciveMessage(Message message){
		messagelist.add(message);
	}
	
	public Message readNextMessage(){
		if(messageindex<messagelist.size()){
			messageindex++;
			return messagelist.get(messageindex-1);
		}
		return null;
	}
	
	public void showMessages(){
		for (Message message : messagelist) {
			System.out.println(message.toString());
		}
	}
	
	public void sendMessage(Message message){
		message.setSender(name);
		server.post(message);
	}
	public MailServer getServer() {
		return server;
	}

	public void setServer(MailServer server) {
		this.server = server;
		this.server.addClient(this);
	}

	public String getName() {
		return name;
	}
	
	
	
}
